
public class GridWorld {

	private State[][] states;

	public GridWorld(int x, int y) {
		initGridWorld(x, y);
	}

	public State getState(Coordinate coordinate) {
		if (coordinate.getX() < 0)
			return null;
		else if (coordinate.getX() > 6)
			return null;
		if (coordinate.getY() < 0)
			return null;
		else if (coordinate.getY() > 6)
			return null;
		return this.states[coordinate.getX()][coordinate.getY()];
	}

	private void initGridWorld(int x, int y) {
		this.states = new State[x][y];
		for (int i = 0; i < x; i++) {
			for (int j = 0; j < y; j++) {
				this.states[i][j] = new State(i, j);
			}
		}
		this.states[0][6] = null;
		this.states[0][3] = null;
		this.states[0][0] = null;
		this.states[1][3] = null;
		this.states[3][6] = null;
		this.states[3][5] = null;
		this.states[3][3] = null;
		this.states[3][1] = null;
		this.states[3][0] = null;
		this.states[5][3] = null;
		this.states[6][0] = null;
		this.states[6][3] = null;
		this.states[6][6] = null;
	}

	public String toString() {
		String result = "***Q-Values*** \n";
		for (int i = this.states[0].length - 1; i >= 0; i--) {
			for (int j = 0; j < this.states.length; j++) {
				result = result.concat(this.states[j][i] + " ");
			}
			result = result.concat("\n");
		}
		return result;
	}

	public State[][] getStates() {
		return this.states;
	}
}
